import smtplib
from email.mime.text import MIMEText
from email.header import Header

smtpserver = 'smtp.126.com'  # 发送邮箱服务器

user = 'lichunmei55@126.com'  # 发送邮箱用户名
password = ' '  # 发送邮箱密码
sender = 'lichunmei55@126.com'  # 发送邮箱
receiver = '787360118@qq.com'  # 接收邮箱
subject = 'python email from lichunmei'  # 发送邮件主题

# 邮件正文
msg = MIMEText('<html><h1>来自python练习的测试邮件</h1></html>', 'html', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['from'] = sender
msg['to'] = receiver

# 连接发送邮件
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(user, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
